<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet">
<link href="__UI__/css/bs3/bui.css" rel="stylesheet">
<link href="__UI__/css/page.css" rel="stylesheet" type="text/css" />

</head>
<body> 
<div class="container">
	<div class="search-grid-container">
		<div class="row">
			<div class="control-group">
				<form id="searchForm" class="form-horizontal">
					<div class="controls">
						<select id="filetype" name="mark">
                        	<option value="">请选择法规集</option>
							<volist name="filetype" id="vo">  
								<option value="{$vo.title}">{$vo.title}</option>
							</volist>
						</select>
					</div>
					<div class="controls">
						<input type="text" class="control-text" name="search" id="search" data-tip="{text:'请输入资料名称'}">
						<button  type="button" id="btnSearch" class="button button-primary">搜索</button>
					</div>
				</form>
			</div>
		</div>
		<div id="grid"></div>
	</div>
</div>
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript">
	top.topManager.closePage('datum_add');
	top.topManager.closePage('datum_edit');
	BUI.use('common/page');
	BUI.use(['common/search','bui/overlay'],function (Search,Overlay){
		var columns = [
			{title:'资料类型',dataIndex:'type',width:100},
			{title:'资料名称',dataIndex:'title',width:300},
			{title:'操作',dataIndex:'',width:100,renderer:function(value,obj){
				var editStr = Search.createLink({
					id:'datum_edit' + obj.id,
					title:'编辑资料',
					text:'编辑',
					href:'{:U("Home/Datum/edit/id/' + obj.id + '")}',
					isClose:true,
				}),
				delStr = '<span class="grid-command btn-del" title="资料删除">删除</span>';
				Search.createLink;
				return editStr + delStr;
			}},
			{title:'',dataIndex:'opt',width:100},
		],
		store = Search.createStore('{:U("Datum/index")}',{
			proxy:{
				save:{removeUrl:'{:U("Datum/index")}'}
			},
			autoSync:true,
			pageSize:10,
			
		}),
		gridCfg = Search.createGridCfg(columns,{
			forceFit:true,
			tbar:{
				items:[
					{text : '<i class="icon-refresh"></i>刷新页面',btnCls : 'button button-small',handler:function(){
						window.location.reload();
					}},
					{text : '<i class="icon-plus"></i>新建资料',btnCls : 'button button-small',handler:function(){
						top.topManager.openPage({
							id:'datum_add',
							title:'新建资料',
							href:'{:U("Datum/add")}',
							isClose:true,
						});
					}},
					{text:'<i class="icon-remove"></i>批量删除',btnCls:'button button-small',handler:delFunction},
				]
			},
			plugins:[BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.RowNumber] 
		});
		var  search = new Search({
			store:store,
			gridCfg:gridCfg,
		}),
		grid = search.get('grid');
		function delFunction(){
			var selections = grid.getSelection();
			delItems(selections);
		}
		function delItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认要删除选中的记录么？',function(){
					$.ajax({
						url:'{:U("Home/Datum/del")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								search.load();
							}else{
								BUI.Message.Alert('删除失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-del')){
				var record = ev.record;
				delItems([record]);
			}
		});
	});
</script>
</body>
</html>